#ifndef MANAGEMENTDIALOG_H
#define MANAGEMENTDIALOG_H

#include <QDialog>
#include <QTableWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QMessageBox>
#include <QHeaderView>
#include <tuple>
#include "databasemanager.h"

QT_BEGIN_NAMESPACE
namespace Ui { class ManagementDialog; }
QT_END_NAMESPACE

class ManagementDialog : public QDialog
{
    Q_OBJECT

public:
    ManagementDialog(QWidget *parent = nullptr);
    ~ManagementDialog();

private slots:
    // 特征管理槽函数
    void on_addFeatureButton_clicked();
    void on_updateFeatureButton_clicked();
    void on_deleteFeatureButton_clicked();
    void on_featuresTableWidget_itemSelectionChanged();
    
    // 规则管理槽函数
    void on_addRuleButton_clicked();
    void on_updateRuleButton_clicked();
    void on_deleteRuleButton_clicked();
    void on_rulesTableWidget_itemSelectionChanged();
    
    // 通用槽函数
    void on_refreshButton_clicked();
    void on_closeButton_clicked();

private:
    Ui::ManagementDialog *ui;
    DatabaseManager *databaseManager;
    
    // 当前选中的项目ID
    int selectedFeatureId;
    int selectedRuleId;
    
    // 初始化函数
    void initializeDatabase();
    void setupTables();
    void connectSignals();
    
    // 数据加载函数
    void loadFeatures();
    void loadRules();
    void refreshData();
    
    // 特征管理函数
    void addFeature();
    void updateFeature();
    void deleteFeature();
    void clearFeatureInputs();
    
    // 规则管理函数
    void addRule();
    void updateRule();
    void deleteRule();
    void clearRuleInputs();
    
    // 工具函数
    void showMessage(const QString &title, const QString &message, QMessageBox::Icon icon = QMessageBox::Information);
    bool validateFeatureInput();
    bool validateRuleInput();
    QStringList parseRuleConditions(const QString &conditionsText);
    QString formatRuleConditions(const QStringList &conditions);
};

#endif // MANAGEMENTDIALOG_H